package com.plwf.lake.service.impl;

import com.plwf.lake.entity.Student;
import com.plwf.lake.mapper.StudentMapper;
import com.plwf.lake.service.StudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentMapper mapper;

    @Override
    public List<Student> query(Map<String, Object> map) {
        return this.mapper.select(map);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean save(Student student) {
        if(student.getStuId()!=null){
            return this.mapper.update(student);
        }else{
            return this.mapper.insert(student);
        }

    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean remove(Integer stuId) {
        return this.mapper.delete(stuId);
    }

    @Override
    public Student find(Integer stuId) {
        return this.mapper.selectOne(stuId);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean enable(Integer id, Integer status) {
        Student student = new Student();
        student.setStuId(id);
        student.setStatus(status);
        return this.mapper.enable(student);
    }

    @Override
    public List<Student> queryAll() {
        return this.mapper.selectAll();
    }

    @Override
    public List<Student> queryReverse(Map<String, Object> map) {
        return this.mapper.selectReverse(map);
    }

    @Override
    public List<Student> queryAllRes() {
        return this.mapper.selectAllRes();
    }

    @Override
    public Student login(Student bean) {
        return this.mapper.login(bean);
    }

    @Override
    public Integer maxId() {
        return this.mapper.maxId();
    }

    @Override
    public Student queryPeo(Integer stuId,Integer classId) {
        return this.mapper.selectPeo(stuId,classId);
    }

    @Override
    public List<Student> queryPeriod(Map<String, Object> map) {
        return this.mapper.selPeriod(map);
    }

    @Override
    public Student querySess(Map<String, Object> map) {
        return this.mapper.selSess(map);
    }

    @Override
    public Student queryReverse2(Integer id) {
        return this.mapper.selectReverse2(id);
    }
}
